package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 破釜沉舟<br/>
 * 砸锅卖铁也不收礼，牺牲自己{0=30#0}%气势值为所有己方成员增加{1=30#0}%的攻击力和防御力
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90103 extends CombatSkill {

	public COMBAT_SKILL_90103(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		// 减自己hp
		CombatUnit source = action.unit;
		ActionEffect effect = action.addTarget(source);
//		target = effect.getUnit(); // 修正目标
		float rate = skill.getParameter(0) / GameStaticConfig.percentBase;
		int damage = (int) (source.getMaxHp() * rate);
		damage = Math.max(damage, 1);
		effect.effect(CombatAttributeType.HP, -damage);
		// 加队友攻防
		List<CombatUnit> units = action.unit.getTeam().all();
		for (int i = 0; i < units.size(); i++) {
			CombatUnit unit = units.get(i);
			if (!unit.isDied()) {
				// attack defense
				action.addBuff(new BUFF(skill, unit));
				action.addBuff(new BUFF2(skill, unit));
			}
		}
	}
	
	// 加攻
	static class BUFF extends CombatBuff {
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner);
			active = true;
			int power = (int) owner.getAttackPower();
			power += power * skill.getParameter(1) / GameStaticConfig.percentBase;
			owner.setAttributeValue(CombatAttributeType.ATTACK_POWER, power);
		}
	}
	
	// 加防
	static class BUFF2 extends CombatBuff {
		public BUFF2(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(1), owner);
			active = true;
			int defense = (int) owner.getDefense();
			defense += defense * skill.getParameter(1) / GameStaticConfig.percentBase;
			owner.setAttributeValue(CombatAttributeType.DEFENSE, defense);
		}
	}

}
